library(tidyverse)
library(haven)
data <- read_csv("Survey_Data.csv")


data<-data%>%
  mutate(treatment= FL_8_DO)%>%
  mutate(treatment=recode_factor(.x=treatment,
                                 `FL_12`="Control",
                                 `FL_9`="Treatment"))%>%
  drop_na(treatment)%>%
  mutate(dv = recode_factor(.x=Q20,
                            `1` = "Extremely likely",
                            `2` = "Moderately likely",
                              `3` ="Slightly likely",
                              `4`="Neither likely nor unlikely",
                              `5`="Slightly unlikely",
                              `6`="Moderately unlikely",
                              `7`="Extremely unlikely"  ))%>%
  drop_na(dv)
  


table(data$dv)


fig1<-ggplot(data=data,
             aes(x=dv, fill=treatment))+
               geom_bar( position=position_dodge())+
  theme_bw()+
  coord_flip()+
  labs(title="Likelihood of voting by treatment", 
       x="Respondent's likelihood of voting", y = "N", color="Treatment")+
  scale_fill_manual(values=c('black','lightgray'), name="Treatment")

fig1             

fig1b<-ggplot(data=data, aes(dv))+
  geom_bar(aes(fill=as.factor(treatment), y = 200*(..count..)/sum(..count..)), position="dodge")+
  theme_bw()+
  coord_flip()+
  labs(title="Reported likelihood of voting by treatment", 
       x="Respondent's likelihood of voting", y = "Percent of respondents\nin the condition", color="Treatment")+
  scale_fill_manual(values=c('black','lightgray'), name="Treatment")

fig1b

fig2<-ggplot(data=manipulation,
             aes(x=abs(afinn)))+
  geom_density()+
  theme_bw()+
  labs( 
       x="Absolute value of the sentiment", y = "")

fig2
data$dv2=7-data$Q20
t.test(as.numeric(dv2)~as.numeric(treatment), data=data)
sd(data$dv2)
